package com.account.book.controller;


import com.account.book.common.response.BaseResult;
import com.account.book.common.response.ResultUtils;
import com.account.book.request.CategoryQueryReqVo;
import com.account.book.request.CategoryReqVo;
import com.account.book.response.CategoryQueryResVo;
import com.account.book.response.CategoryResVo;
import com.account.book.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @author liang-hw
 * @className CategoryController
 * @description 账本分类接口
 * @date 2023/11/09 13:25:55
 */
@Api(tags = {"账本分类接口"})
@RestController
@RequestMapping("/api/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    /**
     * @param @param  categoryReqVo
     * @param request
     * @return @return {@link BaseResult }
     * @author liang-hw
     * @description 新建账本分类
     * @date 2023/11/09 13:26:29
     */
    @ApiOperation(value = "新建账本分类", notes = "新建账本分类")
    @PostMapping("/save")
    public BaseResult save(@Valid @RequestBody CategoryReqVo categoryReqVo, HttpServletRequest request) {
        categoryService.save(categoryReqVo, "/bookCategory", categoryReqVo.getBookId(), request);
        return ResultUtils.success();
    }


    /**
     * @param @param categoryId
     * @param bookId
     * @return @return {@link BaseResult }
     * @author liang-hw
     * @description
     * @date 2023/11/09 13:44:43
     */
    @ApiOperation(value = "移除账本分类", notes = "移除账本分类")
    @GetMapping("/remove")
    public BaseResult remove(@RequestParam("categoryId") String categoryId, @RequestParam("bookId") String bookId) {
        categoryService.remove(categoryId, bookId);
        return ResultUtils.success();
    }

    /**
     * @param @param categoryQueryReqVo
     * @return @return {@link BaseResult }<{@link List }<{@link CategoryResVo }>>
     * @author liang-hw
     * @description 查询分类
     * @date 2023/11/09 13:29:05
     */
    @ApiOperation(value = "查询分类", notes = "查询分类")
    @PostMapping("/findList")
    public BaseResult<List<CategoryResVo>> findList(@Valid @RequestBody CategoryQueryReqVo categoryQueryReqVo) {
        List<CategoryResVo> categoryList = categoryService.findList(categoryQueryReqVo);
        return ResultUtils.success(categoryList);
    }


    /**
     * @param @param bookId
     * @return @return {@link BaseResult }<{@link CategoryQueryResVo }>
     * @author liang-hw
     * @description 根据bookId查询分类
     * @date 2023/11/09 13:30:25
     */
    @ApiOperation(value = "根据bookId查询分类", notes = "根据bookId查询分类")
    @GetMapping("/findBookIdList")
    public BaseResult<CategoryQueryResVo> findBookIdList(@RequestParam("bookId") String bookId) {
        CategoryQueryResVo categoryQueryResVo = categoryService.findBookIdList(bookId);
        return ResultUtils.success(categoryQueryResVo);
    }
}
